﻿using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcTriggerHandGunShootAnimation : AIBaseNode
    {
        float cd;
        
        protected override void OnExecute()
        {
            // 检测自身状态
            AnimationAgent animationAgent = _entity.viewer.animationAgent;
            if (!animationAgent.CanDoNextAnimation())
            {
                EndAction(false);
                return;
            }
            
            // cd
            if (_entity.WeaponSystem.HandleWeapon != null)
            {
                cd = _entity.WeaponSystem.HandleWeapon.Config.shooting_cd;
            }
            else
            {
                cd = 0.1f;
            }
            
            // 射击
            animationAgent.PlayGunFire(); 
        }

        protected override void OnUpdate()
        {
            if (elapsedTime < cd)
            {
                return;
            }
            
            AnimationAgent animationAgent = _entity.viewer.animationAgent;
            if (animationAgent.CanDoNextAnimation())
            {
                EndAction(true);
            }
        }

        
    }
}